import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;

public class Test2 {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add("2");
        arrayList.add("3");
        //顺序表 转为链表
        LinkedList<String> linkedList2 = new LinkedList<>(arrayList);


        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("haha");
        linkedList.add("hello");
        linkedList.add("abc");

        //输出
        System.out.println(linkedList);

        System.out.println("===foreach打印===");
        for (String x: linkedList) {
            System.out.println(x);
        }

        System.out.println("===迭代器打印===");
        ListIterator<String> it = linkedList.listIterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }

        System.out.println("===迭代器反向打印===");
        ListIterator<String> it2 = linkedList.listIterator(linkedList.size());
        while (it.hasPrevious()) {
            System.out.println(it.previous());
        }
    }
}
